Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CORS + Cookies flags #790

Closed
wants to merge 2 commits into from
Closed

CORS + Cookies flags #790

wants to merge 2 commits into from

Conversation

otherview
Copy link
Member

Description

This is a tentative fix for https://github.com/vechain/b3tr/issues/1123#issuecomment-2219331553

Issue:

  • CORS Allowed Origins set to "*" can not be used with "Credentials: true"
    Link with more info here
    The standard suggestion fix seems to be :
    If, instead, you need to adjust the server's behavior, you'll need to change the value of Access-Control-Allow-Origin to grant access to the origin from which the client is loaded.

This PR adds the following flags:
api-allowed-creds and api-allowed-origins that used together changes the response headers so that it's ok to use Cookies and CORS.

api-allowed-creds sets the Access-Control-Allow-Credentials header to true.
api-allowed-origins sets the Access-Control-Allow-Origin to be set as the Origin request.

Example:
Before
Request{ Type:GET, To:www.yahoo.com, Header{'Origin:www.google.com', 'Access-Control-Allow-Credentials: true'}}
Response{ Type:GET, To:www.yahoo.com, Header{Access-Control-Allow-Origin:"*"}} - which fails

With flags enabled
Request{ Type:GET, To:www.yahoo.com, Header{'Origin:www.google.com', 'Access-Control-Allow-Credentials: true'}}
Response{ Type:GET, To:www.yahoo.com, Header{Access-Control-Allow-Origin:"www.google.com", 'Access-Control-Allow-Credentials: true'}} - which is ok

Fixes # (issue)

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)

How Has This Been Tested?

  • Manually tested
  • api_tests.go

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • New and existing E2E tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules
  • I have not added any vulnerable dependencies to my code

@otherview otherview requested a review from a team as a code owner July 15, 2024 16:44
@codecov-commenter
Copy link

Codecov Report

Attention: Patch coverage is 0% with 16 lines in your changes missing coverage. Please review.

Project coverage is 62.63%. Comparing base (e5d76aa) to head (7180749).

Files Patch % Lines
api/api.go 0.00% 8 Missing ⚠️
cmd/thor/main.go 0.00% 8 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #790      +/-   ##
==========================================
- Coverage   62.65%   62.63%   -0.03%     
==========================================
  Files         199      199              
  Lines       18196    18210      +14     
==========================================
+ Hits        11401    11405       +4     
- Misses       5713     5724      +11     
+ Partials     1082     1081       -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@@ -69,6 +69,14 @@ var (
Value: 1000,
Usage: "limit the number of logs returned by /logs API",
}
apiAllowedCredsFlag = cli.BoolFlag{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we add these flags to readme with some kind of description / example please ? 😄

* simplify to one flag

* readme

---------

Co-authored-by: otherview <[email protected]>
@kgapos
Copy link
Member

kgapos commented Jul 24, 2024

Now that google scraps their plan to block 3rd party cookies, perhaps it's a good idea to explore this implementation further?

@otherview otherview marked this pull request as draft August 14, 2024 14:44
Copy link

This pull request has been marked as stale due to inactivity. It will be closed if no further activity occurs. Thank you for your contributions.

@github-actions github-actions bot added the stale PR/ Issue has been marked as stale label Oct 14, 2024
@github-actions github-actions bot closed this Oct 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stale PR/ Issue has been marked as stale
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants